# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=lmdb
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.22
pkgrel=1
pkgdesc="Lightning Memory-mapped Database (mingw-w64)"
arch=('any')
url="https://symas.com/mdb/"
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=("${_realname}-${pkgver}.tar.gz::https://codeload.github.com/LMDB/${_realname}/tar.gz/LMDB_${pkgver}")
sha256sums=('f3927859882eb608868c8c31586bb7eb84562a40a6bf5cc3e13b6b564641ea28')

prepare() {
  cd "${srcdir}/${_realname}-LMDB_${pkgver}/libraries/liblmdb"
  sed -e "s|SOEXT	= .so|SOEXT	= .dll|g" \
      -e "s|liblmdb.so|liblmdb.dll|g" \
      -e "s|ILIBS.*=.*|& liblmdb.dll.a|g" \
      -e "s|\$(SOLIBS)|& -Wl,--out-implib,\$@.a|g" \
      -e "s|/usr/local|${MINGW_PREFIX}|g" \
      -e "\$aliblmdb.dll.a: liblmdb.dll" \
      -i Makefile
}

build() {
  cd "${srcdir}/${_realname}-LMDB_${pkgver}/libraries/liblmdb"
  make clean
  make
}

check() {
  cd "${srcdir}/${_realname}-LMDB_${pkgver}/libraries/liblmdb"
  make test
}

package() {
  cd "${srcdir}/${_realname}-LMDB_${pkgver}/libraries/liblmdb"
  make DESTDIR="${pkgdir}" install
  mv "${pkgdir}${MINGW_PREFIX}/lib/liblmdb.dll" "${pkgdir}${MINGW_PREFIX}/bin"
}
